import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import elementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconVue from '@element-plus/icons-vue'

axios.defaults.baseURL = 'http://127.0.0.1:8088'
axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'

axios.interceptors.request.use(
  config => {
    const team08 = window.sessionStorage.getItem('team08')
    if (team08 !== null && team08 !== '') {
      config.headers.team08 = team08
    }
    return config
  }
)

const app = createApp(App)

const originalError = window.console.error
window.console.error = (...args) => {
  if (
    args[0]?.message?.includes?.('ResizeObserver') ||
    args[0]?.includes?.('ResizeObserver') ||
    args[0]?.toString()?.includes?.('ResizeObserver')
  ) {
    return
  }
  originalError.call(window.console, ...args)
}

app.provide('$axios', axios)

app.use(elementPlus)
for (const [key, component] of Object.entries(ElementPlusIconVue)) {
  app.component(key, component)
}

app.config.globalProperties.$http = axios

app.use(router).mount('#app')

app.use(elementPlus)
